﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace TechControl.BD
{
    class Item_EntregueDB: BaseDB
    {
        private static Item_EntregueDB instance;

        private Item_EntregueDB() { }

        public static Item_EntregueDB getInstance()
        {
            if (instance == null)
            {
                instance = new Item_EntregueDB();
            }
            return instance;
        }

        //retorna valor do ultimo registro inserido.
        public Int64 getLastID()
        {
            Int64 result = 0;

            try
            {
                this.open();
                SqlCommand command = new SqlCommand("select max(id_item_entregue) from tb_item_entregue", this.conn);
                SqlDataReader rdr = command.ExecuteReader();

                while (rdr.Read())
                {
                    result = rdr.GetInt64(0);
                }
            }
            catch (Exception)
            {
                result = 0;
            }
            finally
            {
                this.close();
            }

            return result;
        }

        //inseri um novo rregistro na tasbela.
        public bool insertNewItem(Int64 cod, Int64 codFunc, string nome, Int64 codEquip, string serial, string imei, string marca, string modelo,
                                  string desMod, string data, string rg, string pat, string empresa)
        {
            bool result = false;

            try
            {
                this.open();
                SqlCommand command = new SqlCommand("insert into tb_item_entregue values('" + cod + "', '" + codFunc + "', '" + nome +
                    "', '" + codEquip + "', '" + serial + "', '" + imei + "', '" + marca + "', '" + modelo + "', '" + desMod + "', '" + data +
                    "', '" + rg + "', '" + pat + "', '" + empresa + "');", this.conn);
                command.ExecuteNonQuery();
                result = true;
            }
            catch (Exception)
            { result = false; }
            finally
            {
                this.close();
            }
            return result;
        }

    }
}
